/*** manager ***/
package comm;

import db.DataBase;

public class Products {

  private static String[][] data;
  private static String[] headers;

  
  public static String[][] getData() {
    return data = DataBase.readData(DataBase.PRODUCTS);
  }

  public static String[] getHeaders() {
    return headers = new String[]{
              "ID", "Nome", "Tipo", "Preço", "Quantia em estoque"
            };
  }

  public static String[] getData(int row) {
    getData();
    return data[row];
  }

  public static String[] getData(String id) {
    getData();
    for (String[] s : data) {
      if (s[0].equals(id)) {
        return s;
      }
    }
    return null;
  }

  private static String getID() {
    String id = "";
    id = Integer.toString(((int) (Math.random() * 10000)) + 1);
    for (int i = 0; i < data.length; i++) {
      if (data[i][0].equals(id)) {
        return null;
      }
    }
    return id;
  }

  public static String getValidID() {
    getData();
    String res = null;
    while (res == null) {
      res = getID();
    }
    return res;
  }
}
